package pl.edu.agh.neural.main;

import com.google.common.primitives.Doubles;
import pl.edu.agh.neural.core.INetwork;
import pl.edu.agh.neural.input.FileParsingException;
import pl.edu.agh.neural.input.SimpleNetworkBuilder;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Starter {

	public static void main(String[] args) {
		try {
            Scanner scanner = new Scanner( System.in );
			INetwork network = SimpleNetworkBuilder.buildNetwork("testNetwork.txt");

            while(true) {
                int inputVectorSize = network.getInputVectorSize();
                List<Double> inputValues = new ArrayList<>(inputVectorSize);
                for (int i = 0; i <inputVectorSize; i++) {
                    System.out.printf("Enter value for input %d: ", i);
                    inputValues.add(scanner.nextDouble());
                }

                double[]result = network.evaluate(Doubles.toArray(inputValues));

                for (Double value : result) {
                    System.out.print(value + " ");
                }

                System.out.println();

                char inChar;
                do {
                    System.out.println("Do you wish to continue? (Y/N)");
                    inChar = scanner.next().toUpperCase().charAt(0);
                    if (inChar == 'N') {
                        System.exit(0);
                    }
                } while (inChar != 'Y');
            }
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileParsingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
